import type { User, UserInfo, CodeType } from '@/types/user.d'
import { request } from '@/utils/request'

/**
 * 发送手机验证码
 * @param mobile 发送验证码的手机号
 * @param type 验证码类型
 */
export const sendMobileVerificationCode = (mobile: string, type: CodeType) => {
  return request<{ code: string }>('/code', 'get', { mobile, type })
}

/**
 * 通过密码登录
 * @param mobile 手机号
 * @param password 密码
 */
export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('login/password', 'post', { mobile, password })
}

/**
 * 通过手机验证码登录
 * @param mobile 手机号
 * @param code 验证码
 */
export const loginByMobileVerificationCode = (mobile: string, code: string) => {
  return request<User>('/login', 'POST', { mobile, code })
}

/**
 * 获取用户信息
 */
export const getUserInfo = () => {
  return request<UserInfo>('/patient/myUser', 'get')
}
